#include "GUI_Morph.h"

void	gui_base::init(Vector2D assetID,Morphs type, int a_showState)
{
	assetIndex		= assetID;
	m_ishowState	= a_showState;
	morphType		= type; 
	objectType		= TYPE_GUI; 
	active			= true;
	setScale(1,1,1);
	setRotation(0,0,0);

}
//=====PANEL
void	gui_panel::init(Vector2D AssetID, Vector2D Pos, int a_showState){
	gui_base::init(AssetID,MORPH_PANEL,a_showState);
	m_v3Pos			= Vector3D(float(Pos.x),float(Pos.y),1.0f);	
	dimensions.x	= 10;
	dimensions.y	= 10;
	m_tbTexts		= 0;
	m_iElements		= 0;
	m_iAllocated	= 0;
	setScale(1,1,1);
	setRotation(0,0,0);
};
void	gui_panel::init(Vector2D AssetID, Quad Dims, int a_showState){
	gui_base::init(AssetID,MORPH_PANEL,a_showState);
	m_v3Pos			= Vector3D(float(Dims.x),float(Dims.y),1.0f);	
	dimensions.x	= Dims.width;
	dimensions.y	= Dims.height;
	m_tbTexts		= 0;
	m_iElements		= 0;
	m_iAllocated	= 0;
	setScale(1,1,1);
	setRotation(0,0,0);
};
void	gui_panel::reset(Quad Dims,int a_showState)
{
	gui_base::init(this->assetIndex,MORPH_PANEL,a_showState);
	m_v3Pos			= Vector3D(float(Dims.x),float(Dims.y),1.0f);	
	dimensions.x	= Dims.width;
	dimensions.y	= Dims.height;
}
void	gui_panel::addTextBox(Quad Pos, char* Value)
{
	if(morphType != MORPH_NULL)
	{
		TextBox ToAdd(Value,Pos);
		if(m_iAllocated <= 0){
			m_iAllocated	= oneLength;
			m_tbTexts		= new TextBox[m_iAllocated];
			m_iElements		= 0;
		}

		if(m_iElements == m_iAllocated){
			m_iAllocated += oneLength;
			TextBox* Temp = new TextBox[m_iAllocated];
			for(int i(0); i < m_iElements; i++)	
				Temp[i] = m_tbTexts[i];
			delete m_tbTexts;				//Delete the old pointer	
			m_tbTexts = Temp;				//Point at the new
		}
		m_tbTexts[m_iElements] = ToAdd;
		m_iElements++;
	}
};
void	gui_panel::modifyTBox(Quad Pos, char* Value, int index)
{
	if(index > m_iElements)
		return;
	TextBox Temp(Value,Pos);
	m_tbTexts[index] = Temp;

}

void	gui_panel::modifyText(char* a_message)
{
	m_tbTexts[0].val = a_message;
}

void	gui_panel::update(short currentState)
{
	if(m_ishowState == currentState)	
		active = true;
	else								
		active = false;
}
bool	gui_panel::checkCollision(POINT Mouse){
	if(!(Mouse.x >= m_v3Pos.x && 
		Mouse.y >= m_v3Pos.y &&
		Mouse.x <= m_v3Pos.x + dimensions.x &&
		Mouse.y <= m_v3Pos.y + dimensions.y))
		return false;
	return true;
};
TextBox gui_panel::accessText(short Index)
{
	if(m_iElements > 0)
		return m_tbTexts[Index];
	return TextBox();
};
//=====BUTTON
void	gui_button::init(Vector2D assetID, short a_showState, Quad Dim, buttonType buttonID){
	gui_panel::init(assetID,Dim,a_showState);

	m_v3Pos		= Vector3D(Dim.x,Dim.y,1);
	morphType	= MORPH_BUTTON;
	dimensions.x= Dim.width;
	dimensions.y= Dim.height;
	m_eID		= buttonID;
	m_sPressed	= false;
};
bool gui_button::checkClicked(POINT Mouse)
{

	if(!active)	return false;
	if(!(Mouse.x >= m_v3Pos.x && 
		Mouse.y >= m_v3Pos.y &&
		Mouse.x <= m_v3Pos.x + dimensions.x &&
		Mouse.y <= m_v3Pos.y + dimensions.y))
		return false;
	m_sPressed = true;
	return true;
}


//=====ICON
void	gui_icon::init(Vector2D assetID, short a_showState, Quad Dim, int buttonID)
{
	gui_panel::init(assetID,Dim,a_showState);

	m_v3Pos		= Vector3D(Dim.x,Dim.y,1);
	morphType	= MORPH_ICON;
	dimensions.x= Dim.width;
	dimensions.y= Dim.height;
	m_eID		= buttonID;
	m_sPressed	= false;
	hoverText   = "";
};
//=====INPUT
void	gui_input::init(Vector2D AssetID,Quad Rect,int a_showState, char** textToMod)
{
	gui_panel::init(AssetID,Vector2D(Rect.x,Rect.y),a_showState);
	m_v3Pos		= Vector3D(Rect.x,Rect.y,1);
	morphType	= MORPH_INPUT;

	wordMorph = textToMod;
	gui_panel::addTextBox(Quad(Rect.x+5,Rect.y+10,Rect.width,Rect.height),*textToMod);

}
void	gui_input::update(short currentState)
{
	gui_panel::update(currentState);
	m_tbTexts[0].val = *wordMorph;
};
